package com.lower.service.ipself;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import org.lucksyc.utilindependent.resultview.core.data.ViewData;
import org.lucksyc.utilindependent.resultview.seed.deal.ViewBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bean.Computer;
import com.componentbean.UserNginxSet;
import com.model.ComputerIpModel;

@Service
public class CommonIpSelfInterfaceImpl implements CommonIpSelfInterface {
	
	@Autowired
	ViewBuilder viewBuilder;
	
	@Autowired
	UserNginxSet userset;
	
	@Override
	public ViewData getLocalIpList() {
		List<ComputerIpModel> result = new ArrayList<>();
		Computer computerMyselfDefault = userset.getComputerSelf().getMySelfDefault();
		ComputerIpModel modelMyselfDefault = new ComputerIpModel();
		modelMyselfDefault.setId(String.valueOf(computerMyselfDefault.getId()));
		modelMyselfDefault.setIp(computerMyselfDefault.getIp());
		result.add(modelMyselfDefault);
		if (null != userset.getComputerSelf().getOther()) {
			Iterator<Entry<Integer, Computer>> iterator =userset.getComputerSelf().getOther().entrySet().iterator();
			while (iterator.hasNext()) {
				Computer computerMyself = iterator.next().getValue();
				ComputerIpModel modelMyself = new ComputerIpModel();
				modelMyself.setId(String.valueOf(computerMyself.getId()));
				modelMyself.setIp(computerMyself.getIp());
				result.add(modelMyself);
			}
		}
		return viewBuilder.wrap(result);
	}
}
